<template>
  <div class="page-main oilPriceManage">
    <el-table :data="list" style="width: 100%" height="680" align="center" v-loading="tableLoading">
      <el-table-column
        prop="id"
        label="编号"
        align="center"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="name"
        label="加油站名称"
        align="center"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="spec"
        label="油气号"
        align="center"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="price"
        label="平台价格(元)"
        align="center"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="station_price"
        label="油站价格(元)"
        align="center"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="add_time"
        label="发布时间"
        align="center"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column prop="address" label="操作" align="center">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="danger"
            @click="action('delete',scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="formInline.page"
      :page-sizes="$pageSizeList"
      :page-size="formInline.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    ></el-pagination>
  </div>
</template>

<script>
import { getGasPriceList,deletePrice } from "@/api/gasStation";
export default {
  name: "oilPriceManage",
  data() {
    return {
      formInline: {
        page: 1,
        pageSize: 10
      },
      tableLoading: true,
      list: [],
      total: 0
    };
  },
  mounted() {
    this.initial();
  },
  methods: {
    async initial() {
      this.tableLoading = true;
      let result = await getGasPriceList();
      this.tableLoading = false;
      if (result.code == 200) {
        this.list = result.list.data;
        this.total = result.list.total;
      }
    },
    handleSizeChange(pageSize) {
      this.formInline.pageSize = pageSize;
      this.formInline.page = 1;
      this.initial();
    },
    handleCurrentChange(page) {
      this.formInline.page = page;
      this.initial();
    },
    action(type,row){
      if(type == 'delete'){
        this.$confirm("确定要删除该油价信息吗?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(async () => {
            let result = await deletePrice({id:row.id});
            if(result.code == 200){
              this.$message({
                type: "success",
              })
              this.initial();
            }
          }).catch(() => { });

      }
    }
  }
};
</script>

<style lang="scss" scoped>
.oilPriceManage {
}
</style>
